import os
from config.configs import TEST_DB_HOST, TEST_PORT, DATA_PATH
from tools.tool import read_json_file
from tools.clean_datas import reset_workflow, reset_bonded, wf_clean_settlement
from tools.mongo_tool import MongoDbLink

bs_stock = os.path.join(DATA_PATH, 'bonded.stocks.json')
bs_order = os.path.join(DATA_PATH, 'bonded.orders.json')
wf_payment = os.path.join(DATA_PATH, 'workflow_dev.payments.json')
wf_cost = os.path.join(DATA_PATH, 'workflow_dev.costs.json')


def reset_data():
    """重置保税，workflow订单、库存、结算数据"""
    bs = MongoDbLink(TEST_DB_HOST, TEST_PORT, 'bonded20231023')
    reset_bonded()
    bs_stock_datas = read_json_file(bs_stock)
    bs_order_datas = read_json_file(bs_order)
    bs.insert_many('stocks', bs_stock_datas)
    bs.insert_many('orders', bs_order_datas)
    bs.update_many(doc='orders', cond={"merchantStmtStatus": "finish"},
                   update={"$set": {"merchantStmtStatus": "pending"}})
    bs.close()
    wf = MongoDbLink(TEST_DB_HOST, TEST_PORT, 'workflow_dev')
    reset_workflow()
    wf_costs_datas = read_json_file(wf_cost)
    wf_payments_datas = read_json_file(wf_payment)
    wf.insert_many('payments', wf_payments_datas)
    wf.insert_many('costs', wf_costs_datas)
    wf_clean_settlement()
